package com.tiancheng.trade.payment.channel.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 银联退款状态
 */
@Getter
@AllArgsConstructor
public enum UmsRefundStatusEnum {
    UNKNOWN("UNKNOWN", "不明确的交易状态(需要调退款查询接口确认退款结果)"),
    SUCCESS("SUCCESS", "退款成功"),
    FAIL("FAIL", "退款失败"),
    PROCESSING("PROCESSING", "退款处理中(需要调退款查询接口确认退款结果)"),

    ;
    private String code;
    private String desc;

    public static String getDesc(String code) {
        Optional<UmsRefundStatusEnum> refundStatusEnum = Arrays.stream(UmsRefundStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (refundStatusEnum.isPresent()) {
            return refundStatusEnum.get().getDesc();
        }
        return "";
    }

    public static UmsRefundStatusEnum getByValue(String value) {
        for (UmsRefundStatusEnum refundStatusEnum : values()) {
            if (refundStatusEnum.getCode().equals(value)) {
                return refundStatusEnum;
            }
        }
        return UNKNOWN;
    }
}
